/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jfonia.view.symbols;

import org.jfonia.assets.fonts.Fughetta;
import org.jfonia.connect5.basics.BasicValueNode;
import org.jfonia.connect5.basics.MutableValueNode;
import org.jfonia.connect5.basics.ValueNode;
import org.jfonia.connect5.basics.Node;
import org.jfonia.connect5.basics.Observer;
import org.jfonia.constants.SymbolConstants;

/**
 *
 * @author Rik Bauwens
 */
public class RestSymbol extends PrimitiveStaffSymbol
{
        public RestSymbol(ValueNode<Double> frameX, ValueNode<Double> staffY,
                          MutableValueNode<Double> staffBase, MutableValueNode<Double> postStaffBase,
                          ValueNode<Double> xNode, MutableValueNode<Double> widthNode,
                          ValueNode<Integer> restNode)
        {
                super(frameX, staffY, staffBase, postStaffBase, xNode, widthNode, 
                        new BasicValueNode<Integer>(SymbolConstants.REST_RANK));
                init(restNode);
        }

        private void init(ValueNode<Integer> restNode)
        {
                //Rest
                setRest(restNode.getValue());

                restNode.addObserver(new Observer()
                {
                        public void onNotify(Object source)
                        {
                                setRest(((ValueNode<Integer>) source).getValue());
                        }
                });

        }

        private void setRest(int restId)
        {
                if(restId == SymbolConstants.REST_SEMIBREVE)
                        textGlyph = Fughetta.getGlyph(SymbolConstants.REST_1);
                else if(restId == SymbolConstants.REST_MINIM)
                        textGlyph = Fughetta.getGlyph(SymbolConstants.REST_1_2);
                else if(restId == SymbolConstants.REST_CROTCHET)
                        textGlyph = Fughetta.getGlyph(SymbolConstants.REST_1_4);
                else if(restId == SymbolConstants.REST_QUAVER)
                        textGlyph = Fughetta.getGlyph(SymbolConstants.REST_1_8);
                else if(restId == SymbolConstants.REST_SEMIQUAVER)
                        textGlyph = Fughetta.getGlyph(SymbolConstants.REST_1_16);
                else if(restId == SymbolConstants.REST_DEMISEMIQUAVER)
                        textGlyph = Fughetta.getGlyph(SymbolConstants.REST_1_32);
                textGlyph.setSize(SymbolConstants.SYMBOL_SIZE);
                updateNodes();
        }

        //Prevent that the rank can be changed (fixed)
        @Override
        public void setRank(int rank) {}
}
